import { http } from "../http";
const baseUrl = "/api/dms/users";

export interface UserType {
  id: string;
  name: string;
  userCode: string;
  ogaCode: string;
  encryptedPassword: string;
}

// 注册用户
export interface RegisterType {
  name: string;
  userCode: string;
  encryptedPassword: string;
  ogaCode: string;
  roleId?: number;
}
export const registerAPI = (params: RegisterType) => {
  return http.post(`${baseUrl}/register`, params);
};

// 删除用户
export const deleteUserAPI = (id: string) => {
  return http.delete(`${baseUrl}/deleteUser/${id}`);
};

// 获取公共密钥
export const getPublicKeyAPI = () => {
  return http.get(`${baseUrl}/publicKey`);
};

// 登录
export interface LoginType {
  userCode: string;
  encryptedPassword: string;
}
export const loginAPI = (params: LoginType) => {
  return http.post(`${baseUrl}/login`, params);
};

// 获取用户列表
export interface GetUserListType {
  name?: string;
  ogaCode?: string;
  page: number;
  size: number;
}
export const getUserListAPI = (params: GetUserListType) => {
  return http.post(`${baseUrl}/list`, params);
};
// 修改用户信息
export interface UpdateUserType {
  userCode: string;
  name: string;
  ogaCode: string;
  roleIds: number[];
}
export const updateUserAPI = (params: UpdateUserType) => {
  return http.post(`${baseUrl}/update`, params);
};

// 修改密码
export interface UpdatePasswordType {
  userCode: string;
  oldEncryptedPassword: string;
  newEncryptedPassword: string;
  confirmEncryptedPassword: string;
}
export const updatePasswordAPI = (params: UpdatePasswordType) => {
  return http.post(`${baseUrl}/updatePassword`, params);
};
